<template>
  <div class="side-navbar2-component" :style="componentStyle">
    <div class="sidebar-brand" v-if="显示品牌区">
      <img v-if="品牌图片" :src="品牌图片" alt="Brand" class="brand-image">
      <span v-else class="brand-text">{{ 品牌文字 }}</span>
    </div>
    
    <div class="user-profile" v-if="显示用户资料">
      <div class="avatar-container">
        <img v-if="用户头像" :src="用户头像" alt="Avatar" class="user-avatar">
        <div v-else class="avatar-placeholder" :style="{backgroundColor: 主题颜色}">
          {{ 用户名称.charAt(0).toUpperCase() }}
        </div>
      </div>
      <div class="user-details">
        <div class="user-name">{{ 用户名称 }}</div>
        <div class="user-role">{{ 用户角色 }}</div>
      </div>
    </div>
    
    <div class="sidebar-divider" v-if="显示分隔线"></div>
    
    <div class="sidebar-menu">
      <div class="menu-category" v-if="显示菜单分类">{{ 菜单分类名称 }}</div>
      <div 
        v-for="(item, index) in 菜单项目" 
        :key="index"
        class="menu-item"
        :class="{ 'active': index === 0 }"
      >
        <i :class="getIconClass(index)"></i>
        <span class="menu-text">{{ item }}</span>
      </div>
    </div>
    
    <div class="sidebar-footer" v-if="显示底部">
      <div class="footer-button">
        <i class="el-icon-switch-button"></i>
        <span>{{ 底部按钮文字 }}</span>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'SideNavbar2Component',
  componentName: '侧边导航栏2',
  icon: 'el-icon-s-fold',
  defaultProps: {
    背景颜色: '#ffffff',
    文字颜色: '#333333',
    主题颜色: '#4e73df',
    显示品牌区: true,
    品牌文字: 'DASHBOARD',
    品牌图片: '',
    显示用户资料: true,
    用户名称: 'John Doe',
    用户角色: 'Administrator',
    用户头像: '',
    显示分隔线: true,
    显示菜单分类: true,
    菜单分类名称: 'CORE',
    菜单项目: ['Dashboard', 'Users', 'Products', 'Reports', 'Settings'],
    显示底部: true,
    底部按钮文字: 'Logout'
  },
  props: {
    背景颜色: {
      type: String,
      default: '#ffffff'
    },
    文字颜色: {
      type: String,
      default: '#333333'
    },
    主题颜色: {
      type: String,
      default: '#4e73df'
    },
    显示品牌区: {
      type: Boolean,
      default: true
    },
    品牌文字: {
      type: String,
      default: 'DASHBOARD'
    },
    品牌图片: {
      type: String,
      default: ''
    },
    显示用户资料: {
      type: Boolean,
      default: true
    },
    用户名称: {
      type: String,
      default: 'John Doe'
    },
    用户角色: {
      type: String,
      default: 'Administrator'
    },
    用户头像: {
      type: String,
      default: ''
    },
    显示分隔线: {
      type: Boolean,
      default: true
    },
    显示菜单分类: {
      type: Boolean,
      default: true
    },
    菜单分类名称: {
      type: String,
      default: 'CORE'
    },
    菜单项目: {
      type: Array,
      default: () => ['Dashboard', 'Users', 'Products', 'Reports', 'Settings']
    },
    显示底部: {
      type: Boolean,
      default: true
    },
    底部按钮文字: {
      type: String,
      default: 'Logout'
    }
  },
  methods: {
    getIconClass(index) {
      const icons = [
        'el-icon-s-data',
        'el-icon-user',
        'el-icon-goods',
        'el-icon-document',
        'el-icon-setting'
      ];
      return icons[index] || 'el-icon-menu';
    }
  },
  computed: {
    componentStyle() {
      return {
        backgroundColor: this.背景颜色,
        color: this.文字颜色,
        width: '100%',
        height: '100%',
        boxSizing: 'border-box'
      };
    }
  }
};
</script>

<style scoped>
.side-navbar2-component {
  display: flex;
  flex-direction: column;
  height: 100%;
  box-shadow: 0 0.15rem 1.75rem 0 rgba(58, 59, 69, 0.15);
}

.sidebar-brand {
  padding: 1.5rem 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: v-bind(主题颜色);
  color: white;
}

.brand-image {
  height: 32px;
  max-width: 80%;
  object-fit: contain;
}

.brand-text {
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: 0.05rem;
  text-transform: uppercase;
}

.user-profile {
  padding: 1rem;
  display: flex;
  align-items: center;
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

.avatar-container {
  margin-right: 10px;
}

.user-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
}

.avatar-placeholder {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: bold;
}

.user-details {
  display: flex;
  flex-direction: column;
}

.user-name {
  font-weight: 600;
  font-size: 0.9rem;
}

.user-role {
  font-size: 0.8rem;
  opacity: 0.8;
}

.sidebar-divider {
  height: 0;
  margin: 0.5rem 0;
  border-top: 1px solid rgba(0, 0, 0, 0.1);
}

.sidebar-menu {
  flex: 1;
  padding: 0.5rem 0;
  overflow-y: auto;
}

.menu-category {
  padding: 0.5rem 1rem;
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
  color: rgba(0, 0, 0, 0.4);
}

.menu-item {
  padding: 0.7rem 1rem;
  display: flex;
  align-items: center;
  cursor: pointer;
  transition: all 0.2s;
  border-left: 3px solid transparent;
}

.menu-item:hover {
  background-color: rgba(78, 115, 223, 0.1);
}

.menu-item.active {
  border-left-color: v-bind(主题颜色);
  color: v-bind(主题颜色);
}

.menu-item i {
  margin-right: 0.5rem;
  font-size: 1rem;
}

.sidebar-footer {
  padding: 1rem;
  border-top: 1px solid rgba(0, 0, 0, 0.1);
}

.footer-button {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem;
  background-color: v-bind(主题颜色);
  color: white;
  border-radius: 0.25rem;
  cursor: pointer;
  transition: all 0.2s;
}

.footer-button:hover {
  opacity: 0.9;
}

.footer-button i {
  margin-right: 0.5rem;
}
</style>